using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace Share.UI
{

    [RequireComponent(typeof(Mask))]
    //¿Ø¼þ½¥Èë½¥³ö
    public class UIEffect_Mask : UIEffectBase
    {
        public enum EMaskMode
        {
            UP2Down,
            Down2Up,
            Left2Right,
            Right2Left,
        }

        public EMaskMode m_Mode = EMaskMode.UP2Down;
        [SerializeField]
        float m_Duration = 0.5f;

        // Start is called before the first frame update
        void Start()
        {
            if (GetComponent<Mask>() == null)
            {
                Debug.LogError("UIEffect_Mask requires Mask component on the same GameObject");
                return;
            }
        }

        // Update is called once per frame
        void Update()
        {

        }

        private Vector2 GetTargetSize(EMaskMode mode)
        {
            var rt = GetComponent<RectTransform>();
            Vector2 fullSize = rt.sizeDelta;
            Vector2 zeroSize = Vector2.zero;

            switch (mode)
            {
                case EMaskMode.UP2Down:
                case EMaskMode.Down2Up:
                    return new Vector2(fullSize.x, 0);
                case EMaskMode.Left2Right:
                case EMaskMode.Right2Left:
                    return new Vector2(0, fullSize.y);
                default:
                    return fullSize;
            }
        }

        public override void OnActionEnter()
        {
            var mask = GetComponent<Mask>();
            if (mask == null) return;

            var rt = GetComponent<RectTransform>();
            Vector2 targetSize = rt.sizeDelta;
            rt.sizeDelta = GetTargetSize(m_Mode);
            rt.DOSizeDelta(targetSize, m_Duration).SetEase(Ease.OutQuad);
        }

        public override void DoActionExit()
        {
            var mask = GetComponent<Mask>();
            if (mask == null) return;

            var rt = GetComponent<RectTransform>();
            rt.DOSizeDelta(GetTargetSize(m_Mode), m_Duration).SetEase(Ease.OutQuad);
        }
    }
}
